package controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by yvdedu.com on 2016/10/10.
 */
@WebServlet(urlPatterns = "/get_session")
public class get_session extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        req.setCharacterEncoding("utf-8");
        Object user=req.getSession().getAttribute("user");
        if(user!=null){
            User user1=(User) user;
            ObjectMapper mapper = new ObjectMapper();
            String json = mapper.writeValueAsString(user1);
            resp.getWriter().print(json);
        }
    }
}
